package com.jiuzhe.commercial.ui.resourse;

import android.widget.TextView;

import com.jiuzhe.commercial.R;
import com.jiuzhe.commercial.base.BaseActivity;
import com.jiuzhe.commercial.bean.OrderInfoBean;
import com.jiuzhe.commercial.constant.Constants;
import com.jiuzhe.commercial.http.CallBack;
import com.jiuzhe.commercial.http.HttpClient;
import com.jiuzhe.commercial.utils.SPUtil;
import com.jiuzhe.commercial.utils.UIUtils;

import java.util.HashMap;

import butterknife.BindView;

/**
 * Created by huanghao on 2018/5/9.
 */

public class OrderDetailsActivity extends BaseActivity {
    @BindView(R.id.tv_name)
    TextView tvName;
    @BindView(R.id.tv_state)
    TextView tvState;
    @BindView(R.id.tv_start_time)
    TextView tvStartTime;
    @BindView(R.id.tv_end_time)
    TextView tvEndTime;
    @BindView(R.id.tv_adress)
    TextView tvAdress;
    @BindView(R.id.tv_roomPrice)
    TextView tvRoomPrice;
    @BindView(R.id.tv_bood)
    TextView tvBood;
    @BindView(R.id.tv_time)
    TextView tvTime;

    @Override
    protected void loadViewLayout() {
        setContentView(R.layout.layout_order_details);
        setTitle("订单详情");
    }

    @Override
    protected void loadData() {
        String orderId = getIntent().getStringExtra("id");

        HashMap<String, String> map = new HashMap<>();
        String token = SPUtil.getString(this, Constants.TOKEN);
        String id = SPUtil.getString(this, Constants.ID);
        String autoSignStr = Constants.ORDER.substring(Constants.ORDER.lastIndexOf("0/") + 1) + "?token=";
        String signStr = UIUtils.Md5(autoSignStr + token);
        map.put("token", id);
        map.put("sign", signStr);
        map.put("id", orderId);

        HttpClient.post(this, Constants.ORDER, map, new CallBack<OrderInfoBean>() {
            @Override
            public void onSuccess(OrderInfoBean result) {
                tvName.setText(result.getOccupantName());
                tvStartTime.setText(result.getStartDate());
                tvEndTime.setText(result.getEndDate());
                tvAdress.setText(result.getAddress());
                tvRoomPrice.setText("房费 " + result.getSkuPrice());
                tvBood.setText("压金 " + result.getSkuBond());
                tvTime.setText(result.getCreateTime());
                itemStatus(result.getRoomStatus());
            }
        });
    }

    private void itemStatus(int status) {
        switch (status) {
            case 1://待支付 白色
                tvState.setText("待支付");
                break;
            case 2://已支付 浅蓝
                tvState.setText("已支付");
                break;
            case 3://已退房 灰色
                tvState.setText("已退房");
                break;
            case 4://已过期 白色
                tvState.setText("已过期");
                break;
            case 5://已取消 白色
                tvState.setText("已取消");
                break;
            case 6://已入住 红色
                tvState.setText("已入住");
                break;
            case 7://已完成 白色
                tvState.setText("已完成");
                break;
            default:
                break;
        }
    }
}
